"""
@name : 面向对象
@author : shiyaling
@projectname : xsfh
"""
#作业编写日志记录装饰器
#比如执行了func1函数，那就日志记录“执行了func1函数，花费多久时间” ，日志的格式要包含时间
#日志要输出到文件（sc.log）和屏幕

import time
import logging
def func1(func):
    def inner(a,b):
        start = time.time()
        result = func(1,2)
        end = time.time()
        total = end - start
        logger = logging.getLogger()
        fh = logging.FileHandler("sc.log",encoding='utf-8')
        ch = logging.StreamHandler()
        formatter = logging.Formatter("%(asctime)s-%(levelname)s:%(message)s")
        fh.setFormatter(formatter)
        logger.addHandler(fh)
        logger.addHandler(ch)
        logger.setLevel(logging.DEBUG)
        logger.warning(f"执行了{func.__name__},花费了{total}")
    return inner
@func1
def add(a,b):
    time.sleep(2)
    return a+b

print(add(1,2))

